package com.purplesoft.zettl.Adapters;

import com.purplesoft.zettl.R;
import com.purplesoft.zettl.DatabaseTables.TblCategories;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

public class ManageAttributesCategoriesListAdapter extends CursorAdapter {

	// layout inflater object variable
	private LayoutInflater inflater;
	
	private TextView tvAttributeColor, tvAttribute;
	
	private int CategoryColor, CategoryName;
	
	public ManageAttributesCategoriesListAdapter(Context context, Cursor cursor) {
		super(context, cursor);
		// Instantiate layout inflater object
		inflater = LayoutInflater.from(context);
		CategoryColor = cursor.getColumnIndex(TblCategories.Columns.CategoryColor);
		CategoryName = cursor.getColumnIndex(TblCategories.Columns.CategoryName);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		tvAttributeColor = (TextView) view.findViewById(R.id.tvAttributeColor_ManageAttributesRow);
		tvAttribute = (TextView) view.findViewById(R.id.tvAttribute_ManageAttributesRow);
		
		tvAttributeColor.setBackgroundColor(Color.parseColor(cursor.getString(CategoryColor)));
		tvAttribute.setText(cursor.getString(CategoryName));
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		return inflater.inflate(R.layout.manage_attributes_row, null);
	}
}
